package com.xzlf.aspct;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Aspect
@Component
@Slf4j
public class MyAspct {

    @After("execution(* com.xzlf.service.impl.*.sendMail(..))")
    @Around("execution(public * com.xzlf.service.impl.MailServiceImpl.sendMaill(..)) || execution(public * com.xzlf.service.impl.PrintServiceImpl.print(..))")
    public void taskAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        long starTime = System.currentTimeMillis();
        MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();
        Method method = methodSignature.getMethod();
        Object[] args = proceedingJoinPoint.getArgs();
        log.info("任务方法{}，方法参数{}", method.getName(), args);
        proceedingJoinPoint.proceed(args);
        long endTime = System.currentTimeMillis();
        log.info("总耗时：{}", endTime - starTime);

    }
}
